#ifndef MEDIADECODE_H
#define MEDIADECODE_H
#include <functional>
#include <unistd.h>

#include "LogUtils.h"
#include "stringutils.h"

extern "C"
{
#include "libavformat/avformat.h"
#include "libavcodec/avcodec.h"
}

class MediaDecode
{
public:
    MediaDecode();
    ~MediaDecode();

    int init(const char *video_file_path,bool isDecodeVideo,bool isDecodeAudio);
    int decode(const std::function<int(AVPacket *,AVFrame *,int, AVRational)> &video_func,
               const std::function<int(AVPacket *,AVFrame *,int, AVRational)> &audio_func,
               const std::function<int(void)> &finish_func);
    void deInit();
    AVCodecContext* getVideoAVCodecContext();
    AVCodecContext* getAudioAVCodecContext();

private:
    int i = 0;
    int video_index,audio_index = -1;
    AVCodec *video_dec = nullptr;
    AVCodecContext *video_codec_ctx_,*audio_codec_ctx_= nullptr;
    AVCodecParameters *video_avCodecParameters,*audio_avCodecParameters;
    AVPacket packet;
    AVFrame *dec_frame = nullptr;
    AVFormatContext *ifmt_ctx = nullptr;
    bool isDecodeVideo,isDecodeAudio;
};

#endif // MEDIADECODE_H
